<template>
  <div class="search-list">
    <transition-group tag="ul" name="list">
      <li :key="item" class="search-item" @click="selectItem(item,$event)" v-for="item in searches">
        <span class="text">{{item}}</span>
        <span class="icon" @click.stop="deleteOne(item,$event)">
          <i class="icon-delete"></i>
        </span>
      </li>
    </transition-group>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      searches: {
        type: Array,
        default: []
      }
    },
    methods: {
      selectItem(item, event) {
        if (!event._constructed) {
          return
        }
        this.$emit('select', item)
      },
      deleteOne(item, event) {
        if (!event._constructed) {
          return
        }
        this.$emit('delete', item)
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped="">
  @import "~common/scss/const";
  @import "~common/scss/mixin";

  .search-list {
    .search-item {
      display: flex;
      align-items: center;
      height: 40px;
      overflow: hidden;
      &.list-enter-active, &.list-leave-active {
        transition: all 0.1s;
      }
      &.list-enter, &.list-leave-to {
        height: 0;
      }
      .text {
        flex: 1;
        color: $color-text-l;
        font-size: $font-size-small;
      }
      .icon {
        @include extend-click;
        .icon-delete {
          font-size: $font-size-small;
          color: $color-text-d;
        }
      }
    }
  }
</style>
